package com.game.raceroom.player.effect
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.utils.getTimer;
	
	import com.util.SwfUtil;
	import com.game.raceroom.player.Player;
	public class CaroticEffect extends Effect
	{
		private var actor:Player;
		public function CaroticEffect(actor:Player,eid:int,max:int)
		{
			this.effectId=eid;
			this.actor=actor;
			startTime=getTimer();
			maxTime=max;
			this.effectType=EFFECT_TYPE_CAROTIC;
			loadMovie();
		}
		private var loadOk:Boolean=false;
         public override function update():Boolean{
         	if(!loadOk) return true;
            mc.x=actor.actorDisp.mc.x+actor.actorDisp.mc.width/2-mc.width/2;
            mc.y=actor.actorDisp.mc.y+actor.actorDisp.mc.height/2-mc.height/2;
	         if(getTimer()-startTime>this.maxTime){
	         	actor.actorDisp.removeChild(mc);
		          valid=false;
	         }

        	 return true;
         }
         public override function destroy():Boolean{
         	if(!loadOk) return true;
            actor.actorDisp.removeChild(mc);
            this.valid=false;
            return true;
         }
         protected var myLoader:Loader;
         
		public function loadMovie():void{
			myLoader=new Loader();
		    myLoader.contentLoaderInfo.addEventListener(
  	        Event.COMPLETE,function (e:Event):void{initEftOk(e)});
            myLoader.loadBytes(SwfUtil.getEffectSwfStream(SwfUtil.EFT_NAME_CAROTIC));
      
		}
		private var mc:MovieClip;
        public function initEftOk(e:Event):void{
            mc = myLoader.content as MovieClip;

            mc.alpha=0.7;
			actor.actorDisp.addChild(mc);
			loadOk=true;

        } 
	}
}